﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure;
using FtpWorkerRole;

namespace FtpWebRole.Entities
{
    public class PerformanceContext : TableServiceContext
    {
        private CloudStorageAccount _account;
        private readonly string _tableName = "WADPerformanceCountersTable";

        public PerformanceContext(CloudStorageAccount account)
            : base(account.TableEndpoint.AbsoluteUri, account.Credentials)
        {
            _account = account;

            var client = new CloudTableClient(_account.TableEndpoint.AbsoluteUri, _account.Credentials);
            client.CreateTableIfNotExist(_tableName);
        }

        public IQueryable<PerformanceEntity> Records
        {
            get
            {
                return CreateQuery<PerformanceEntity>(_tableName); 
            }
        }
    }
}